﻿using Futajma.MigrationStudio.DataDefinition;
using Futajma.MigrationStudio.GenericImporter;
using Futajma.MigrationStudio.GenericPersistance;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace Futajma.MigrationStudio.GenericPersistance
{
    public class WrongVersionFileException : Exception
    {
        public WrongVersionFileException(string message)
            : base(message)
        {
        }
    }

    [ObfuscationAttribute(Exclude = true, ApplyToMembers = true)]
    public class ProjectData
    {
        ProjectData()
        {
            //ActionItemHandler = new ActionItemHandler();
            GovernanceData = new GovernanceData(true);
            ProjectParameter = new ProjectParameter();
        }

        public ProjectData(/*ActionItemHandler actionItemHandler,*/ GovernanceData governanceData, ProjectParameter projectParameter, IImporter importer)
        {
            //ActionItemHandler = actionItemHandler;
            GovernanceData = governanceData;
            ProjectParameter = projectParameter;
            Importer = importer;
        }

        public static string CurrentDefinitionVersion { get { return "1.3"; } }

        public static bool CheckCompatibility(string currentVersion)
        {
            return currentVersion == CurrentDefinitionVersion;
        }

        public Futajma.MigrationStudio.GenericImporter.IImporter Importer { get; set; }

        //public ActionItemHandler ActionItemHandler { get; set; }

        public GovernanceData GovernanceData { get; set; }

        public ProjectParameter ProjectParameter { get; set; }

    }
    //[ObfuscationAttribute(Exclude = true, ApplyToMembers = true)]
    //public class ProjectParameter
    //{
    //    public void ResetProject()
    //    {
    //        SelectedSharePointItemId = ProjectVersion = 0;
    //        ProjectIsCommited = false;
    //    }

    //    public int SelectedSharePointItemId { get; set; }

    //    public int ProjectVersion { get; set; }

    //    public bool ProjectIsCommited { get; set; }

    //    public static ProjectParameter LoadXml(Stream stream)
    //    {
    //        XmlSerializer serializer = new XmlSerializer(typeof(ProjectParameter));
    //        var projectParameter = (ProjectParameter)(serializer.Deserialize(stream));
    //        return projectParameter;
    //    }

    //    public static StringBuilder Save(ProjectParameter projectParameter)
    //    {
    //        XmlWriterSettings settings = new XmlWriterSettings();
    //        settings.Encoding = new UnicodeEncoding(false, false);
    //        settings.Indent = true;
    //        //settings.CheckCharacters = false;
    //        settings.OmitXmlDeclaration = true;

    //        var serializer = new XmlSerializer(typeof(ProjectParameter));
    //        StringBuilder sb = new StringBuilder();
    //        using (XmlWriter writer = XmlWriter.Create(sb, settings))
    //        {
    //            serializer.Serialize(writer, projectParameter);
    //        }
    //        return sb;
    //    }



    //}

}
